---@class GT.ui.model.countdown 倒计时
---@field t GT.timer 计时器
GT.ui.model.countdown = class()



function GT.ui.model.countdown:ctor()
    self.ui = {}
    self.prefab = {}
    self.tick={}
    self.time={}
    self.prefab["倒计时"] = GT.ui.prefab.obj({
        module = "c2bb47e6-d83c-4b6c-aa62-e37ad689c790",
        parent = "panel_2",
    })
    self.flushed = {}

    local p = self.prefab["倒计时"]

    self.ui["self"] = p:child(GT.ui, "倒计时")
    self.ui["text"] = p:child(GT.ui.control.label, "倒计时文本")
    self:hide()
end


---@param time number 时间
---@param text string 计时器前缀
---@param time_call timer_callback 计时器回调
function GT.ui.model.countdown:set(time,text,time_call)
    self.time=GT.timer.obj({
        count = 1,
        delay = time,
        immediately = false,
        callback = function(data, t)
            self:hide()
            time_call(data, t)
            tick.del(self.tick)
        end
    })
    self.tick=tick.add(function (uuid)
        self.ui["text"].binding.text=(text or '倒计时：')..self.time:get_remaining_time()
    end)
    self:show()
end

function GT.ui.model.countdown:show()
    self.ui["self"].binding.show = true
end

function GT.ui.model.countdown:hide()
    self.ui["self"].binding.show = false
end
